package com.sinosoft.bee.services.proposal.mapper;

import com.sinosoft.bee.services.proposal.entity.proposal.ProposalProduct;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: TrickerL
 * @Description: bee
 * @Date: Create in 15:35 2018/5/16
 * @Modified By:
 */
@Mapper
@Repository
public interface ProposalProductMapper {

    /**
     * 新增险种信息
     * @param proposalProduct
     * @return
     */
    @Insert("INSERT INTO proposal_product (\n" +
            "  proposal_id,\n" +
            "  risk_code,\n" +
            "  insured_id,\n" +
            "  main_risk_code,\n" +
            "  risk_name,\n" +
            "  insure_rank,\n" +
            "  stand_prem,\n" +
            "  prem,\n" +
            "  discount,\n" +
            "  amnt,\n" +
            "  mult,\n" +
            "  pay_intv,\n" +
            "  pay_end_year,\n" +
            "  pay_end_year_flag,\n" +
            "  pay_years,\n" +
            "  insu_year,\n" +
            "  insu_year_flag,\n" +
            "  insu_years,\n" +
            "  get_deductibles,\n" +
            "  get_rate,\n" +
            "  get_year,\n" +
            "  get_year_flag,\n" +
            "  get_years,\n" +
            "  create_user,\n" +
            "  gmt_create,\n" +
            "  modified_user,\n" +
            "  gmt_modified,\n" +
            "  is_deleted\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{proposalId},\n" +
            "    #{riskCode},\n" +
            "    #{insuredId},\n" +
            "    #{mainRiskCode},\n" +
            "    #{riskName},\n" +
            "    #{insureRank},\n" +
            "    #{standPrem},\n" +
            "    #{prem},\n" +
            "    #{discount},\n" +
            "    #{amnt},\n" +
            "    #{mult},\n" +
            "    #{payIntv},\n" +
            "    #{payEndYear},\n" +
            "    #{payEndYearFlag},\n" +
            "    #{payYears},\n" +
            "    #{insuYear},\n" +
            "    #{insuYearFlag},\n" +
            "    #{insuYears},\n" +
            "    #{getDeductibles},\n" +
            "    #{getRate},\n" +
            "    #{getYear},\n" +
            "    #{getYearFlag},\n" +
            "    #{getYears},\n" +
            "    #{createUser},\n" +
            "    #{gmtCreate},\n" +
            "    #{modifiedUser},\n" +
            "    #{gmtModified},\n" +
            "    #{isDeleted}\n" +
            "  );")
    Integer insertProposalProduct(ProposalProduct proposalProduct);

    /**
     * 删除险种
     * @param proposalProduct
     * @return
     */
    @Delete("delete from proposal_product where risk_code=#{riskCode}")
    Integer deleteProposalMain(ProposalProduct proposalProduct);

    /**
     * 查询所有险种
     * @return
     */
    @Results(id = "Product", value = {
            @Result(property = "proposalId", column = "proposal_id"),
            @Result(property = "riskCode", column = "risk_code"),
            @Result(property = "insuredId", column = "insured_id"),
            @Result(property = "mainRiskCode", column = "main_risk_code"),
            @Result(property = "riskName", column = "risk_name"),
            @Result(property = "insureRank", column = "insure_rank"),
            @Result(property = "standPrem", column = "stand_prem"),
            @Result(property = "prem", column = "prem"),
            @Result(property = "discount", column = "discount"),
            @Result(property = "amnt", column = "amnt"),
            @Result(property = "mult", column = "mult"),
            @Result(property = "payIntv", column = "pay_intv"),
            @Result(property = "payEndYear", column = "pay_end_year"),
            @Result(property = "payEndYearFlag", column = "pay_end_year_flag"),
            @Result(property = "payYears", column = "pay_years"),
            @Result(property = "insuYear", column = "insu_year"),
            @Result(property = "insuYearFlag", column = "insu_year_flag"),
            @Result(property = "insuYears", column = "insu_years"),
            @Result(property = "getDeductibles", column = "get_deductibles"),
            @Result(property = "getRate", column = "get_rate"),
            @Result(property = "getYear", column = "get_year"),
            @Result(property = "getYearFlag", column = "get_year_flag"),
            @Result(property = "getYears", column = "get_years"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "gmtCreate", column = "gmt_create"),
            @Result(property = "modifiedUser", column = "modified_user"),
            @Result(property = "gmtModified", column = "gmt_modified"),
            @Result(property = "isDeleted", column = "is_deleted"),
    })
    @Select("select * from proposal_product")
    List<ProposalProduct> selectAllProductInfo();

    /**
     * 修改险种prem通过险种编码
     * @param proposalProduct
     */
    @Update("update proposal_product set prem=#{prem} where risk_code=#{riskCode};")
    void updateByCode(ProposalProduct proposalProduct);

}
